<?php
 include "counter.php";
?>
<?php pagehead("Operation statistics") ?>
<BODY bgcolor="white">
<?php pagetop() ?>
<h1>Operation counts against the counter tables</h1>

These statistics are generated from the counter log.
<p>
Operations against the persons table affect the person
count and statistics.<br>
Operations against the machine table affect the machine count
and statistics.<br>
Operations on the users table are logins, and most other updates.<br>
Operations on the frozen table indicate users being frozen or thawed.
<p>
<?php
	$days = 30;
	$firstday = strftime("%Y-%m-%d 00:00:00",
				time() - 60*60*24*$days);
	$lastday = strftime("%Y-%m-%d 23:59:59",
				time());
	$tables = array("persons", "machines", "users", "frozen");
?>
The statistics are from <?php echo $firstday ?> to <?php echo $lastday ?>.

<?php
        
	$sql = "select substring(date, 1, 10) as m,
	     count(*), tablename, operation from f_log
	     where date > '$firstday' and date < '$lastday'
	     group by m, tablename, operation order by m desc";

        $placeq = mysql_query($sql);
        while ( $place = mysql_fetch_array($placeq)) {
	    $ops["Sum"][$place[2]][$place[3]] += $place[1];
	    $ops[$place[0]][$place[2]][$place[3]] = $place[1];
#	    print("<tr><td>" . $place[0] . "<td>" . $place[1]
#	    . "<td>" . $place[2] . "<td>" . $place[3] . "\n");
#	    $tables[$place[2]] = 1;
        }
?>
<table border>
<?php
	print "<tr><th>Date";
        foreach ($tables as $table) {
            print "<th colspan=3>$table";
	}
	print "\n<tr><th>";
        foreach ($tables as $table => $nonsense) {
            print "<th>New<th>Update<th>Delete";
	}
	print "\n";
	# Amazingly, php returns entries in CREATION TIME order....
	# so we don't need to sort the entries here.
	foreach ($ops as $date => $arr) {
	    print "<tr><td>$date";
	    foreach ($tables as $table) {
	        foreach (array("new", "update", "delete") as $op) {
		    print "<td>" . $ops[$date][$table][$op];
		}
            }
        }

?>
</table>
<?php pagebottom() ?>
</body>
</html>


